package com.weixin.program.utils;

import com.alibaba.fastjson.JSON;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;

public class TemplateUtil {

    /**
     * 封装已打卡通知消息
     *
     * @param toUserId
     * @param toUserName
     * @param templateId
     * @return
     */
    public static String buildNoticeDoneMsg(String toUserId, String toUserName, String templateId) {
        // 具体消息
        HashMap<String, Object> name = new HashMap<>();
        name.put("value", toUserName);
        name.put("color", "#173177");

        HashMap<String, Object> time = new HashMap<>();
        String nowTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        time.put("value", nowTime);
        time.put("color", "#173177");

        HashMap<String, Object> remark = new HashMap<>();
        remark.put("value", "收到该通知,表明您已打卡！");
        remark.put("color", "#0000FF");

        // 封装data对象
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", name);
        data.put("time", time);
        data.put("remark", remark);

        // 封装textMsg对象
        HashMap<String, Object> textMsg = new HashMap<>();
        textMsg.put("touser", toUserId);
        textMsg.put("template_id", templateId);
        textMsg.put("data", data);
        String jsonString = JSON.toJSONString(textMsg);
        return jsonString;
    }

    /**
     * 封装未打卡提醒消息
     *
     * @param toUserId
     * @param toUserName
     * @param templateId
     * @return
     */
    public static String buildRemindMsg(String toUserId, String toUserName, String templateId) {
        // 具体消息
        HashMap<String, Object> name = new HashMap<>();
        name.put("value", toUserName);
        name.put("color", "#173177");

        HashMap<String, Object> date = new HashMap<>();
        String nowTime = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        String amPm = HolidayUtil.getAmPm();
        date.put("value", nowTime + amPm);
        date.put("color", "#FF0000");
        // 封装data对象
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", name);
        data.put("date", date);

        // 封装textMsg对象
        HashMap<String, Object> textMsg = new HashMap<>();
        textMsg.put("touser", toUserId);
        textMsg.put("template_id", templateId);
        textMsg.put("data", data);
        String jsonString = JSON.toJSONString(textMsg);
        return jsonString;
    }

    /**
     * 封装未打卡通知消息
     *
     * @param toUserId
     * @param toUserName
     * @param templateId
     * @return
     */
    public static String buildNoticeMsg(String toUserId, String toUserName, String templateId) {
        // 具体消息
        HashMap<String, Object> name = new HashMap<>();
        name.put("value", toUserName);
        name.put("color", "#173177");

        HashMap<String, Object> time = new HashMap<>();
        String nowTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        time.put("value", nowTime);
        time.put("color", "#173177");

        HashMap<String, Object> remark = new HashMap<>();
        remark.put("value", "收到该通知,表明您未打卡！");
        remark.put("color", "#FF0000");

        // 封装data对象
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", name);
        data.put("time", time);
        data.put("remark", remark);

        // 封装textMsg对象
        HashMap<String, Object> textMsg = new HashMap<>();
        textMsg.put("touser", toUserId);
        textMsg.put("template_id", templateId);
        textMsg.put("data", data);
        String jsonString = JSON.toJSONString(textMsg);
        return jsonString;
    }
}
